/** @file Command.h
    @class Command
    @brief Base command class
*/
#ifndef __Command_h_
#define __Command_h_

#include "Model.h"
#include "BitStream.h"
#include "PlayerAvatar.h"
#include "GameObject.h"
#include "DifferentCommands.h"
#include <string>
#include <sstream>

using namespace std;
class Command {
public:
	/**
	* @brief The empty constuctor
	*/
	Command () {}
	
	/**
	* @brief The constructor
	*/
	Command (unsigned int playerId) : m_playerId(playerId) {}
	
	/**
	* @brief The destructor
	*/
	virtual ~Command (void) {}
	
	/**
	* @brief Executes the command on argument model
	*/
	virtual bool execute(Model *model) = 0;
	
	/**
	* @brief Returns the game object id which this command is attached to
	*/
	int getPlayerId(void) {
		return m_playerId;
	}

	/**
	* @brief Saves the command to a output file stream
	*/
	virtual void save(ofstream &ofs) {
    ofs.write((char*) &m_playerId, sizeof(unsigned int));
  }

	/**
	* @brief Loads a command from input file stream
	*/
  virtual void load(ifstream &ifs) {
    ifs.read((char*) &m_playerId, sizeof(unsigned int));
  }

	/**
	* @brief Saves the command to a bit stream
	*/
  virtual void save(RakNet::BitStream &ofs) {
    ofs.Write((char*) &m_playerId, sizeof(unsigned int));
  }
	
	/**
	* @brief Loads a comand from a bit stream
	*/
  virtual void load(RakNet::BitStream &ifs) {
    ifs.Read((char*) &m_playerId, sizeof(unsigned int));
  }
	
	/**
	* @brief Returns the string of the game object id
	*/
	string toString() {
		stringstream ss;
		ss << m_playerId;
		return ss.str();
	}

private:
	/**
	* @brief Game object id to which this command is attached to
	*/
	unsigned int m_playerId;
};

#endif